package net.aaa.hotel.controller;

import net.aaa.hotel.dao.HTypeDao;
import net.aaa.hotel.dao.TRuzhudetailDao;
import net.aaa.hotel.dao.TXufangDao;
import net.aaa.hotel.entity.TRuzhudetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ruzhu")
public class RuzhuDetailController {
    @Autowired
    TRuzhudetailDao ruzhudetailDao;
    @Autowired
    TXufangDao xufangDao;
    @Autowired
    HTypeDao typeDao;
    @RequestMapping("rzdetail")
    @ResponseBody
    public Map getRudetailByRoomid(String roomid){
      //  System.out.println(" 房间号 "+roomid);
        List<Map> detail = ruzhudetailDao.getRuzhuDetailByRoomId(roomid);
    //    System.out.println("detail "+ detail.size());
        Map map = detail.get(0);
        Integer flag = Integer.parseInt(map.get("status")+"");
        if(flag == 1){
            // 根据入住id到续房表里查找对应id的最大离开时间
            List<Map> record = xufangDao.getRecordByRZid(map.get("id") + "");
            map.put("outdate",record.get(0).get("endtime"));
        }
        // 获取对应房间类型的信息
//        Map roomtype = typeDao.searchType(map.get("roomtype") + "");
//        map.put("money",roomtype.get("money"));
        return map;
    }

//    @RequestMapping("append")
//    @ResponseBody
//    /**
//     * 换房成功后要改变旧房间与新房间的状态
//     */
//    public int appendRuzhuRecord(TRuzhudetail ruzhudetail){
//        int detail = ruzhudetailDao.addRuzhuDetail(ruzhudetail);
//        return detail;
//    }
}
